package com.gla.dao;

import com.gla.entity.Commodity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommodityMapper {
    @Select("SELECT * FROM COMMODITY WHERE shop_id = #{shop_id} AND p_o_u = 0 AND isdel < 1")
    List<Commodity> selectCommodity0ByShopId(Integer shop_id);

    @Select("SELECT * FROM COMMODITY WHERE shop_id = #{shop_id} AND p_o_u = 1 AND isdel < 1")
    List<Commodity> selectCommodity1ByShopId(Integer shop_id);

    @Select("SELECT * FROM COMMODITY WHERE id = #{id}")
    Commodity getCommodityById(Integer id);

    @Update("UPDATE COMMODITY SET isdel = 1 WHERE id = #{id}")
    void delCommodityById(Integer id);

    @Update("UPDATE COMMODITY SET name = #{name}, price = #{price}, number = #{number}, type_id = #{type_id}, details = #{details}, introduction = #{introduction}, photo = #{photo} WHERE id = #{id}")
    void updateCommoditByIdPOU(Integer id, String name, Float price, Integer number, Integer p_o_u, Integer type_id, String details, String introduction, String photo);

    @Insert("INSERT INTO COMMODITY (name, price, number, p_o_u, type_id, shop_id, details, introduction, photo, isdel) VALUES (#{name}, #{price}, #{number}, #{p_o_u}, #{type_id}, #{shop_id}, #{details}, #{introduction}, #{photo}, 0)")
    void insertCommodit(String name, Float price, Integer number, Integer p_o_u, Integer type_id, Integer shop_id, String details, String introduction, String photo);

    @Update("UPDATE COMMODITY SET number=#{number} WHERE id=#{commodity_id}")
    void updateNumber(Integer commodity_id,Integer number);

    @Delete("DELETE FROM COMMODITY WHERE id=#{commodity_id}")
    void deleteCommodityById(Integer commodity_id);
}
